package com.suyu.websocket.controller;

import com.suyu.websocket.server.SocketServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * User: Ray.Shaw <p />
 * Time: 2018/7/18 09:11  <p />
 * Version: V1.0  <p />
 * Description:  <p />
 */
@RestController
public class WebSocketRestController {

    @Autowired
    private SocketServer socketServer;

    @GetMapping("getD")
    public Map hello() {
        int num = socketServer.getOnlineNum();
        String str = socketServer.getOnlineUsers();
        List<String> list = null;
        if (str.length() > 2) {
            str = str.substring(0,str.length()-1);
            String [] strs = str.split(",");
            list =  Arrays.asList(strs);
        }

        Map map = new HashMap();
        map.put("num", num);
        map.put("list", list);


        return map;
    }
}
